<script setup>

import {findCourseAPI} from '@/apis/home'
import {ref,onMounted} from 'vue'

const courList = ref([])
const getCourList = async()=>{
    const res = await findCourseAPI()
    courList.value = res.data.list
}

onMounted(()=>{
    getCourList()
})
 function dateFormat(time) {
      var date = new Date(time);
      var year = date.getFullYear();
      
      var month =
        date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
      var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    //   var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    //   var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    //   var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // 拼接
      return year + "-" + month + "-" + day;
    }
</script>

<template>

    <div class="course-list" >
        <div class="head">
            <h2>推荐课程</h2>
            <el-button round>  <RouterLink :to="`/course`">查看更多+</RouterLink></el-button>
        </div>
        <ul>
             <li v-for="item in courList" :key="item.id">
                <RouterLink :to="`/courseintro/${item.id}`">
                <img :src=item.img />
                <div class="miaoshu dot">
                <span class="title ">{{ item.name }}</span>
                <div class="bottom">
                    <div class="count">
                        <p>{{item.studiedNumber}} 学习</p>
                        <p>
                        <i class="iconfont icon-zan"></i>
                        {{item.likeNumber}} 
                        </p>
                    </div>
                    <span class="datatime">{{dateFormat(item.createTime)}}</span>
                    <p class="depart">@达利不太圆 </p>
                </div>
                </div>
                </RouterLink>
           </li>          
        </ul>
  
    </div>
    
</template>

<style scoped>
.course-list {
    margin-top: 30px;
}
.head {
    display:flex;
    justify-content: space-between;
}
.course-list ul{
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
   
}

ul li {
  box-shadow: 0px 0px 0px rgba(0,0,0,0.2);
  transition: box-shadow 0.3s;
  border:1px solid #EBEEF5;
}

ul li:hover {
  box-shadow: 3px 5px 10px rgba(0,0,0,0.3);
}
.course-list ul li{
    list-style: none;
    width: 205px;
    height: 240px;
    margin-right: 18px;
      /* border: 1px solid #000; */
    background-color: #fff;
     border-radius: 5px;
     margin-bottom: 30px;
}
ul li:nth-child(5n){
    margin-right: 0;
}
li img{
    width: 100%;
    height: 120px;
     border-radius: 5px;

}
li .count{
    margin-top: 15px;
    display: flex;
    color:#999;
    /* margin-bottom: 5px; */
    font-size: 14px;
   
}
li .datatime {
    color:#999;
    font-size: 14px;
}
li .count p{
    margin-right: 20px;
}
li .miaoshu{
    padding: 0 10px;
}
li .depart{
    font-size: 14px;
    color:#ccc;

}
.dot {
    display: inline-block;
    width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>
